//
// Created by DELL on 2023/3/24.
//
#include <iostream>
#include <new>

struct alignas(8) SA1
{
    uint32_t i1;
    uint32_t i2;
};

struct SB1
{
    bool b;
    SA1 sa;
};

struct alignas(4) SA2
{
    uint32_t i1;
    uint32_t i2;
};

struct SB2
{
    bool b;
    SA2 sa;
};

struct alignas(64) SB3
{
    SB3() noexcept = default;
    ~SB3() noexcept = default;

    SB2 sb21;
    SB2 sb22;
};


int main()
{
    std::cout << "alignas(8) sizeof(SB1): " << sizeof(SB1) << " ,  align: " << alignof(SB1) << std::endl;

    std::cout << "alignas(4) sizeof(SB2): " << sizeof(SB2) << " ,  align: " << alignof(SB2) << std::endl;

    // std::cout << "Default new align: " << __STDCPP_DEFAULT_NEW_ALIGNMENT__ << std::endl;
    std::cout << "Max align: " << alignof(std::max_align_t) << std::endl; // 这个是基础类型的最多对齐值

//    auto pAlignedType = new (std::align_val_t{32}) SB3;
    auto pAlignedType = new SB3;

    if (reinterpret_cast<uint64_t>(pAlignedType) % 64 == 0)
    {
        std::cout << "align to 64" << std::endl;
    }
    else
    {
        std::cout << "not align" << std::endl;
    }

    delete pAlignedType;

    return 0;
}


